package com.wyx.regexp;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 王艺锡
 * @version 1.0
 * 字符匹配符的使用
 */
public class regExp02 {
    public static void main(String[] args) {

        String content = "basBA Sb_#$AS1 45d";
        //1.[a-z]:匹配a-z之间的任意字符  [A-Z]:匹配A-Z之间的任意字符
        //String regStr = "[a-z]";
        //String regStr = "[A-Z]";

        //注:java中默认不区分大小写，如果要区分大小写需要使用(?i)
        //(?i)bas表示字符bas不区分大小写
        //b(?i)as表示as不区分大小写
        //b((?i)a)s表示a不区分大小写
        //String regStr = "(?i)bas";
        //String regStr = "b((?i)a)s";

        //String regStr = "bas";

        //2.[0-9]表示匹配0-9之间的任意数字
        //String regStr = "[0-9]";

        //3.[^a-z]:匹配不在a-z之间的任意字符  [^A-Z]:匹配不在A-Z之间的任意字符
        //String regStr = "[^a-z]";
        //String regStr = "[^A-Z]";

        //4.[^0-9]表示匹配不在0-9之间的任意数字
        //String regStr = "[^0-9]";

        //String regStr = "[abcd]";//匹配abcd中的任意字符
        //String regStr = "[^abcd]";//匹配不是abcd中的任意字符

        //String regStr = "\\d";//匹配0-9的任意数字
        //String regStr = "\\D";//匹配不在配0-9的任意字符
        //String regStr = "\\w";//匹配任意数字，字母和下划线
        //String regStr = "\\W";//匹配不是任意数字，字母和下划线
       // String regStr = "\\s";//匹配任何空白字符(空格，制表位)
       // String regStr = "\\S";//匹配任何非空白字符(空格，制表位)
        //String regStr = ".";//匹配除了\n之外的所有字符,如果要匹配.则需要加上转义字符\\.

        //选择匹配符
        String regStr = "ba|#|s";//匹配ba或者#或者s

        //或者在创建Pattern对象时，指定Pattern.CASE_INSENSITIVE,也可以不区分大小写
        Pattern pattern = Pattern.compile(regStr);
        //Pattern pattern = Pattern.compile(regStr,Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()){
            System.out.println("找到" + matcher.group(0));
        }

    }
}
